package io.aircraft.modules.log.controller;

import io.aircraft.common.Utils.ExcelUtils;
import io.aircraft.common.annotation.LogOperation;
import io.aircraft.common.page.PageData;
import io.aircraft.common.utils.Result;
import io.aircraft.modules.log.dto.SysLogWorkDTO;
import io.aircraft.modules.log.excel.SysLogWorkExcel;
import io.aircraft.modules.log.service.SysLogWorkService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 作业日志
 *
 * @author Cycle gengruyi01@163.com
 * @since 1.0.0 2022-11-21
 */
@RestController
@RequestMapping("sys/log/work")
public class SysLogWorkController {
    @Autowired
    private SysLogWorkService sysLogWorkService;

    @GetMapping("page")
    @RequiresPermissions("sys:log:work")
    public Result<PageData<SysLogWorkDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<SysLogWorkDTO> page = sysLogWorkService.page(params);

        return new Result<PageData<SysLogWorkDTO>>().ok(page);
    }

    @GetMapping("export")
    @LogOperation("导出")
    @RequiresPermissions("sys:log:work")
    public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
        List<SysLogWorkDTO> list = sysLogWorkService.list(params);

        ExcelUtils.exportExcelToTarget(response, null, list, SysLogWorkExcel.class);
    }
}